﻿using UnityEngine;
using System.Collections;

public class MainCheckBox : ObjectBase
{
    Transform m_On;
    Transform m_Off;
    Transform m_Disable;

	public string m_Sound = "UI_button";

    public bool IsChecked
    {
        get { return m_IsChecked; }
        set 
        { 
            m_IsChecked = value;
            SetState();
        }
    }
    bool m_IsChecked = false;   

    public bool isEnabled 
    { 
        get
        {
            return enabled; 
        } 
        set
        {
            enabled = value;
            SetDisable();
        } 
    }

	void Awake()
    {
        m_On = transform.Find("on");
        m_Off = transform.Find("off");       
        m_Disable = transform.Find("disable");

        SetState();
    }

	/*
    void OnPress(bool isPressed)
    {
		if (isEnabled == true && isPressed == false && IsChecked == false)
		{
			IsChecked = true;
		}
    }
    */

	void OnClick()
	{
		SoundController.PlaySound(m_Sound);
		IsChecked = true;
	}

    void SetDisable()
    {
        if (m_Disable != null)
            m_Disable.gameObject.SetActive(!isEnabled);
        if (m_On != null)
            m_On.gameObject.SetActive(isEnabled);
        if (m_Off != null)
            m_Off.gameObject.SetActive(isEnabled);
    }

	void SetState()
    {
        m_Off.gameObject.SetActive(!IsChecked);
        m_On.gameObject.SetActive(IsChecked);
    }
}
